<?php
		$aryGet	= $this->input->get(NULL, TRUE);
		if(is_array(@$aryGet))
		{
			$controller_base_path = $this->uri->segment(1) . '/'.$this->uri->segment(2).'/?'.http_build_query($aryGet);
			$sort_by 	= @$aryGet['sort_by'];
			$sort_order = @$aryGet['sort_order'];
			unset($aryGet['per_page']);
			unset($aryGet['sort_by']);
			unset($aryGet['sort_order']);
			$qs = http_build_query($aryGet); 
		}
		else
		{
			$qs = '';	
		}
										
     	$pagination_links = $this->pagination->create_links();
		$sess_prefix = "list_sess_" . $this->uri->segment(1) . '_'; // controller name
	
		if (isset($dataOthers["controller_base_path"]))
		{
			$controller_base_path = $dataOthers["controller_base_path"];
		}
?>


<div class="successfull" style="display:<?php echo ($this->session->flashdata('userMesg') ? 'block' : 'none') ?>;margin-top:15px; ">
    <?php echo $this->session->flashdata('userMesg'); ?>  
</div>
<div class="errorMsg" style="display:<?php echo ($this->session->flashdata('errMsg') ? 'block' : 'none') ?> ">
    <?php echo $this->session->flashdata('errMsg'); ?>  
</div>

<div class="midContainer">

	<!-- STARTS : Add Button -->
	<?php if( isset($dataOthers['addLink']) ) { ?>
    	<div class="extra_links" style="padding:5px 0px; float:right; " align="right">
        	<a class="button" href="<?php echo base_url().$dataOthers['addLink']['url']; ?>"><span><?php echo $dataOthers['addLink']['caption']; ?></span></a>
      	</div>
         <div style="clear:both"></div>
	<?php } ?>
    <!-- ENDS : Add Button -->
    
	<!-- STARTS : Search section -->
    
    <?php 
		if( isset($dataOthers['searchPanelView']) && $dataOthers['searchPanelView'] != '' )
		{
			$this->load->view($dataOthers['searchPanelView'], $dataOthers);		
		}
	?>
     <!-- ENDS : Search section -->

     <div>
     
     	<!-- Start Heading -->
         <div class="headingBox">
            <div class="FloatLeft"><img src="<?php echo imageUrl(); ?>red_leftRound.jpg" width="5" height="24" alt="" /></div>
             <div class="red_midRound" style="width:992px;"><?php if (isset($dataOthers["page_heading"])) echo ($dataOthers["page_heading"]); ?></div>
            <div class="FloatLeft"><img src="<?php echo imageUrl(); ?>red_rightRound.jpg" width="5" height="24" alt="" /></div>
        </div>
        <!-- END Heading -->
        
        
        <div class="whiteBox" style="padding:3px;">

        <form name="frmLicenseSearch" id="frmLicenseSearch"  method="post" action="<?php echo base_url() . $controller_base_path; ?>">
            <!-- DIV START Search Button and pagination part -->
             
           <div> 
            
           <!-- <div class="pagination hidePanel" style="float:left; width:390px;">
				<?php echo $pagination_links; ?>
            </div>-->
           <?php if( ! isset($dataOthers['hide_record_detail']) ){?>     
           <div class="hidePanel" style="font-family:Arial; font-size: 11px;color:#006600;line-height:20px; width:170px; margin-left:auto; margin-right:auto;">
               Displaying <?= $start ?>-<?= $end ?> of <?= $total_rows ?> result(s).
           </div>
           <?php } ?>
           
           
              <?php if( ! isset($dataOthers['hide_search_colums']) ){?>
               <div style="padding-right:5px; float:right; margin-top:-20px;">
                    <input type="submit" class="submitBtn_sml" value="">
              </div>
              <?php } ?>
              
              
                <?php
				//$this->session->userdata('sess_user_type') == 'supervisor'
                if ($this->session->userdata('sess_user_type') == 'admin' && $this->session->userdata('admin_Id') == 3782)
                {
					if($total_rows>0)
					{	
                   ?>
                            <div style="padding-right:5px; float:right; margin-top:-20px;">	
                                <input type="button" name="csv_export" class="gridPrint hidePanel" onclick="window.print() ;" />
                            </div>
                            <div style="padding-right:5px; float:right; margin-top:-20px;">	
                                <input type="button" name="csv_export" class="gridCSVExport hidePanel"  title="Export to CSV" onclick="location.href='<?= base_url() . $controller_base_path . "&export=1&export_type=csv"; ?>'" />
                            </div>
	                   <?php }
					   else
					   {?>
                        <div style="padding-right:5px; float:right; margin-top:-20px;">	
                                <input type="button" name="csv_export" class="gridCSVExport hidePanel"  title="Export to CSV" onclick="alert('Can not export 0 records')"  />
                            </div>
                            
	                       <?php
					   }
                    
                }
                ?>
                </div>
                <!-- DIV END Search Button and pagination part -->

                <div style="clear:both;"></div>
                <div style="overflow:auto;width:991px;">
                    <table width="100%" border="0" align="center" cellspacing="0" cellpadding="1">
                        <tr>
                            <td height="35" colspan="2">
                              <table width="100%" cellspacing="5" cellpadding="2" class="subContentTable">
                                     <tr>
                                        <?php
										
										if( isset($dataOthers['show_serial_no']) )
										{ ?>
											 <td height="22" class="head3" width="4%" nowrap="nowrap" > Sr # </td>
										<?php 
										}
										
                                        $totalCount = count($dataFields);
                                        if (isset($dataFields) && count($dataFields) > 0)
                                        {
											//varDump($dataFields);
                                            foreach ($dataFields as $dataFieldsKey => $dataFieldsVal)
                                            {
												 //if need to be hidden on grid
                                                if (isset($dataFieldsVal['hide_on_grid']) && $dataFieldsVal['hide_on_grid'] == 1)
                                                {
                                                    continue;
                                                }
												
												if( isset($dataFieldsVal['sort']) )
												{
													$link = "<a href=?".($qs. '&sort_by='.$dataFieldsKey.'&sort_order='.(isset($sort_order) && $sort_order == 'asc' && $dataFieldsKey == $sort_by ? 'desc' : 'asc'))."> " . $dataFieldsVal["dataFieldHeading"] . "</a>";													
												}else
												{
													$link = $dataFieldsVal["dataFieldHeading"];
												}
												
                                                ?>
                                                <td height="22" class="head3" >
                                                <?php echo $link; 
														//display_sort_img($dataFieldsKey);
														?>
                                                    <div class="FloatLeft" style="width: 86px;">
                                                		    	
                                                    </div>
                                                </td>
                                                <?php
                                            }
                                        }
                                        ?>
                                    </tr>
                                   
                                    <?php if( ! isset($dataOthers['hide_search_colums']) ){?>
                                   		
                                     <tr class="hidePanel" >
                                     	<?php
                                     	if( isset($dataOthers['show_serial_no']) )
										{ ?>
											 <td >&nbsp;  </td>
										<?php 
										}
                                    
                                        $totalCount = count($dataFields);

                                        //nowing puttign boxes for search
                                        if (isset($dataFields) && count($dataFields) > 0)
                                        {
                                            foreach ($dataFields as $dataFieldsKey => $dataFieldsVal)
                                            {
                                                //if need to be hidden on grid
                                                if (isset($dataFieldsVal['hide_on_grid']) && $dataFieldsVal['hide_on_grid'] == 1)
                                                {
                                                    continue;
                                                }

                                                $dataFieldType = isset($dataFieldsVal["dataFieldType"]) ? $dataFieldsVal["dataFieldType"] : '';
												
												$dataFieldClass= isset($dataFieldsVal["dataFieldClass"]) ? $dataFieldsVal["dataFieldClass"] : '';
												$str_field_width = '100px;';
												/*if($dataFieldClass == 'date_field'){
													$str_field_width = '80px;';
													$str_td_width = "100";
												}*/
                                                $attributes = "";

                                                if (isset($dataFieldsVal["attribute"]))
                                                {
                                                    //adding attribute of fields 
                                                    foreach ($dataFieldsVal["attribute"] as $event => $method)
                                                    {
                                                        $attributes .= " $event=\"$method\" ";
                                                    }
                                                }
                                                ?>
                                                <td   bgcolor="#f2f2f2" class="boderrightWhiteDL" >
                                                    <?php
                                                    //if text box need to be placed
                                                    if (isset($dataFieldType) && $dataFieldType == "text")
                                                    {

                                                        ?>
                                                        <input type="text" name="<?php echo $sess_prefix . ($dataFieldsKey); ?>" id="<?php echo ($dataFieldsKey); ?>" style="width:<?=$str_field_width?>;"  value="<?php if (trim($this->session->userdata($sess_prefix . $dataFieldsKey)) != "") echo (trim($this->session->userdata($sess_prefix . $dataFieldsKey))); ?>" <?php echo $attributes; ?> class="<?=$dataFieldClass?>" />
                                                        <?php
														
                                                    }

                                                    //if combo box needs to be placed
                                                    if (isset($dataFieldType) && $dataFieldType == "combo")
                                                    {
                                                        $comoboxItems = $dataFieldsVal["dataFieldVals"][$dataFieldsKey];
                                                        ?>							
                                                        <select name="<?php echo $sess_prefix . ($dataFieldsKey); ?>" style="width:120px;" id="<?php echo ($dataFieldsKey); ?>" <?php echo $attributes; ?>>
                                                            <option value="">Select</option>
                                                            <?php
                                                            if (!isset($dataFieldsVal["dataFieldVals"]['no_populate']) ||
                                                                    $dataFieldsVal["dataFieldVals"]['no_populate'] != 1)
                                                            {
                                                                if (isset($comoboxItems) && count($comoboxItems) > 0)
                                                                {
                                                                    foreach ($comoboxItems as $comoboxItemsKey => $comoboxItemsVals)
                                                                    {
                                                                        ?>
                                                                        <option value="<?php echo ($comoboxItemsKey); ?>" <?php if (trim($this->session->userdata($sess_prefix . $dataFieldsKey)) != "" && $this->session->userdata($sess_prefix . $dataFieldsKey) == $comoboxItemsKey) echo ("selected"); ?>><?php echo ($comoboxItemsVals); ?></option>
                                                                    <?php
                                                                    }
                                                                }
                                                            }
                                                            ?>
                                                        </select>
        <?php } ?>	

                                                </td>
                                            <?php
                                            }
                                        }
                                        ?>

                                    </tr>
                                    
                                    <?php } // end if  hide panel ?>
                                     					  
                                    <?php
                                    $countRowNo = 0;
                                     if (isset($results) && count($results) > 0)
                                    {
										//varDump($results);exit;
										
                                        $count = $start;
                                        foreach ($results as $resultsKey => $resultsVal)
                                        {
										    $tr_bgcolor = preg_match("/1$|3$|5$|7$|9$/", $countRowNo++) ? "bgcolor='#ffffff'" : "bgcolor='fff1d5'";
										  
                                            ?>
                                            <tr <?=$tr_bgcolor; ?> id="listing_tr_<?=$count;?>" >
                                            
                                            <?php
												if( isset($dataOthers['show_serial_no']) )
												{ ?>
													 <td align="center"> <?php echo $count++; ?> </td>
												<?php 
												}
                                            
                                               
                                                if (isset($dataFields) && count($dataFields) > 0)
                                                {
													
                                                    foreach ($dataFields as $dataFieldsKey => $dataFieldsVal)
                                                    {
														 //if need to be hidden on grid
														if (isset($dataFieldsVal['hide_on_grid']) && $dataFieldsVal['hide_on_grid'] == 1)
														{
															continue;
														}
														
														$bg_color = '';
														$fg_color = '';
														
														if(isset( $dataFieldsVal['field_alias'] ) && !empty($dataFieldsVal['field_alias']))
														{
															$dataFieldsKey =  $dataFieldsVal['field_alias'];
														}
														
														if( isset($dataFieldsVal['color_setting']) )  // color setting, pass color index is used here
														{
															$bg_color_arr = $dataFieldsVal['color_setting']['bg_color'];
															$fg_color_arr = $dataFieldsVal['color_setting']['fg_color'];
 															
															if( isset( $bg_color_arr[$resultsVal[$dataFieldsKey]]) )
																$bg_color = 'background-color:'.$bg_color_arr[$resultsVal[$dataFieldsKey]].';';
															if( isset( $fg_color_arr[$resultsVal[$dataFieldsKey]]) )
																$fg_color = 'color:'.$fg_color_arr[$resultsVal[$dataFieldsKey]].';';	
 														}
 														
                                                        $resultValue = "";
                                                        if (isset($dataFieldsVal['selectCol']))
                                                        {
                                                            $resultValue = $resultsVal[$dataFieldsVal['selectCol']];
                                                        }
                                                        else if (isset($dataFieldsVal["dataFieldVals"]))
                                                        {
                                                            if (isset($dataFieldsVal["dataFieldVals"][$dataFieldsKey][$resultsVal[$dataFieldsKey]]))
                                                                $resultValue = $dataFieldsVal["dataFieldVals"][$dataFieldsKey][$resultsVal[$dataFieldsKey]];
                                                        }
														else if (isset($dataFieldsVal["comma_seperated"]))
                                                        {
														  $resultValue =  parseComaSeparatedValues($resultsVal[$dataFieldsKey], $dataFieldsVal["comma_seperated"] );
                                                        }
														else if(isset($dataFieldsVal['link']))
														{
															$linkUrl = $dataFieldsVal['url'];
															preg_match("/\{(.*?)\}/ ", $linkUrl, $matches);
															$link_field_name = isset($matches[1]) ? $matches[1] : '';
															$linkUrl = str_replace("{".$link_field_name."}", $resultsVal[$link_field_name], $linkUrl);
															$resultValue = $linkUrl;
															
															$link_attributes = '';
															if( isset($dataFieldsVal['link_attributes']) )
															{
																$link_attributes = $dataFieldsVal['link_attributes'];
															}
															
															
															$url = base_url() . $linkUrl;
															if( $dataFieldsKey == 'delete' )
															{
																$link_attributes .= ' onclick="confirm_delete(\''. $url.'\')"';
																$url = 'javascript:void(0)';	
															}
																														
															
															if( isset( $dataFieldsVal['link_image']) )
															{
																$resultValue = '<a '.$link_attributes.' href="' . $url . '"><img src="' . imageUrl() .$dataFieldsVal['link_image'].'" /></a>';
															}
															else
															{	
																$link_caption = '';
																if( isset($dataFieldsVal['link_caption']) ) {
																	$link_caption = $dataFieldsVal['link_caption'];
																} else if( isset($dataFieldsVal['dataFieldHeading']) ) {
																	$link_caption = $dataFieldsVal['dataFieldHeading'];
																}
																
																$resultValue = '<a '.$link_attributes.' href="' . $url . '">'.$link_caption.'</a>';
															}
														}
														else
                                                        {
                                                            $resultValue = $resultsVal[$dataFieldsKey];
                                                        }

                                                        //if any formating needs to be applied
                                                        if (isset($dataFieldsVal['formater']) && $dataFieldsVal['formater'] != "" && $resultValue != "")
                                                        {
                                                            if ($resultValue == "")
                                                            {
                                                                eval("\$resultValue = '-';");
                                                            }
                                                            else
                                                            {
                                                               $formater = str_replace("{field}", $resultValue, $dataFieldsVal['formater']);
																eval("\$resultValue = $formater;");
                                                            }
                                                        }
                                                        
														$style = '';
														if( isset($dataFieldsVal['style']) ) {
															$style = $dataFieldsVal['style'];
														}
														
														$cell_attributes = '';
														if( isset($dataFieldsVal['cell_attributes']) ) {
															$cell_attributes = $dataFieldsVal['cell_attributes'];
														}
														
														/*style=" <?=$bg_color;?> <?=$fg_color; ?>; <?=$style?>"*/
														?>
                                                        
                                                        
                                                        <td  <?=$cell_attributes; ?> >
                                                        <?php 
															echo $resultValue;
														?>
                                                        </td>
                                                    <?php
                                                    }// end foreach column names
                                                }//if column exists
                                               
                                                ?>	
                                            </tr>		
                                            <?php
                                            }// end foreach rows, records
                                        }
                                        else
                                        {
                                            ?>
                                        <tr> <td colspan="15" align="center"> No Record found </td> <tr>
                                            <?php
											
											
                                        }
                                        ?>
                                    <tr>
                                        <td  colspan="<?php echo ($totalCount); ?>" align="center"> <ul class="paging"><?php echo $pagination_links; ?></ul></td>
                                    </tr>									  
                                </table></td>
                        </tr>
                    </table>
                </div>
                </form>
            </div>
        <div style="height:7px;">
            <div class="boxleftBtm"></div>
            <div class="boxmidBtm" style="width:987px;"></div>
            <div class="boxrightBtm"></div>
        </div>
    </div>

    <div class="divFix"></div>
</div>